package com.campus.client.controller;


import com.campus.client.net.ClientConnector;
import com.campus.common.message.AdminAccountManagementResponse;
import com.campus.common.vo.Admin;

import javax.swing.*;
import java.io.IOException;
import java.util.List;

public class AdminAccountManagementController {
    private ClientConnector connector;

    public AdminAccountManagementController(ClientConnector connector) {
        this.connector = connector;
    }

    public List<Admin> getAdmins() throws ClassNotFoundException, IOException {
        AdminAccountManagementResponse resp = connector.listAdmins();
        return resp.getAdmins();
    }

    public boolean addAdmin(Admin admin) throws ClassNotFoundException, IOException {

        AdminAccountManagementResponse resp = connector.addAdmin(admin);
        return resp.isSuccess();
    }
    public boolean deleteAdmin(String id) throws ClassNotFoundException, IOException {
        AdminAccountManagementResponse resp = connector.deleteAdmin(id);
        return resp.isSuccess();
    }

    public List<Admin> searchAdmins(String adminId) throws ClassNotFoundException, IOException {
        AdminAccountManagementResponse resp = connector.searchAdmins(adminId);
        return resp.getAdmins();
    }

    // 可选：结束会话时关闭连接
    public void closeConnection() throws IOException {
        connector.close();
    }
}
